package actionbean;

import net.sf.json.JSONObject;
import net.sourceforge.stripes.action.ActionBeanContext;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.HandlesEvent;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.UrlBinding;
import controller.webservice.WebServiceCtrl;

@UrlBinding(BaseActionBean.WEBSERVICE_PREFIX + "manual-round/{$event}")
public class AdminRoundActionBean extends BaseActionBean {
	private ActionBeanContext context;
	private WebServiceCtrl wsCtrl = new WebServiceCtrl();
	private JSONObject result;
	private String title;

	public JSONObject getResult() {
		return result;
	}

	public String getTitle() {
		return title;
	}

	@Override
	public void setContext(ActionBeanContext context) {
		this.context = context;
	}

	@Override
	public ActionBeanContext getContext() {
		return context;
	}

	@HandlesEvent("start")
	public Resolution startRound() {
		// Set standard HTTP/1.1 no-cache headers.
		getContext().getResponse().setHeader("Cache-Control",
				"private, no-store, no-cache, must-revalidate");

		// Set standard HTTP/1.0 no-cache header.
		getContext().getResponse().setHeader("Pragma", "no-cache");

		title = "Start";
		result = wsCtrl.processStartRoundRequest();
		return new ForwardResolution("/admin/round-response.jsp");
	}

	@HandlesEvent("stop")
	public Resolution stopRound() {
		// Set standard HTTP/1.1 no-cache headers.
		getContext().getResponse().setHeader("Cache-Control",
				"private, no-store, no-cache, must-revalidate");

		// Set standard HTTP/1.0 no-cache header.
		getContext().getResponse().setHeader("Pragma", "no-cache");

		title = "Stop";
		result = wsCtrl.processStopRoundRequest();
		return new ForwardResolution("/admin/round-response.jsp");
	}
}
